#ifndef __RCO_CMD_HANDLER_H__
#define __RCO_CMD_HANDLER_H__

#include "dircache/dircache.h"
#include "rcodef/rcointerface.h"
#include <QDir>
#include <QFileInfoList>
#include <QLibrary>
#include "..\Download\Iface.h"


namespace rco
{

class RcoIODevice;

class CommandsHander
{
public:
	bool Init();

	CmdHandlerResult Do(RcoCommandHead*, const RcoBuffer*, RcoIODevice*, RcoBuffer*);
private:
	IRCommandHandle* const * m_ppCmdHandlers;
};

class CopyCommandHandler
	: public IRCommandHandle
{
public:
	virtual CmdHandlerResult Do(RcoCommandHead*, const RcoBuffer*, RcoIODevice*, RcoBuffer*);
};

//class MoveCommandHandler
//	: public IRCommandHandle
//{
//public:
//	virtual CmdHandlerResult Do(const RcoCommandHead*, const QByteArray*);
//
//};
//
//class DeleteCommandHandler
//	: public IRCommandHandle
//{
//public:
//	virtual CmdHandlerResult Do(const RcoCommandHead*, const QByteArray*);
//
//};
//
//class MkdirCommandHandler
//	: public IRCommandHandle
//{
//public:
//	virtual CmdHandlerResult Do(const RcoCommandHead*, const QByteArray*);
//
//};
//
//class TouchCommandHandler
//	: public IRCommandHandle
//{
//public:
//	virtual CmdHandlerResult Do(const RcoCommandHead*, const QByteArray*);
//
//};
//
//class CDCommandHandler
//	: public IRCommandHandle
//{
//public:
//	virtual CmdHandlerResult Do(const RcoCommandHead*, const QByteArray*);
//
//private:
//	QDir	m_dir;
//};
//
//class LSCommandHandler
//	: public IRCommandHandle
//{
//public:
//	virtual CmdHandlerResult Do(const RcoCommandHead*, const QByteArray*);
//
//
//};
//

struct Iterface;
class DLCommandHandler
	: public IRCommandHandle
{
public:
	virtual CmdHandlerResult Do(RcoCommandHead* rcoCmdHead, const RcoBuffer* bytes, RcoIODevice* inDevice, RcoBuffer* outDevice);
	DLCommandHandler():m_Interface(NULL){}
private:
	void _dl_115_Download();
	void _dl_115_c_Download();
	 typedef Iterface *(* CREATEFUNCPTR)();
private:
	enum {DL_115 = 1,DL_115_C = 3};

	QString			m_DownloadName;
	QLibrary *		m_DownloadDll;
	Interface *		m_Interface;
};

class GetCommandHandler
	: public IRCommandHandle
{
public:
	GetCommandHandler();
	~GetCommandHandler();

	void ResetMe();
	virtual CmdHandlerResult Do(RcoCommandHead* rcoCmdHead, const RcoBuffer* bytes, RcoIODevice* inDevice, RcoBuffer* outDevice);

private:
	void AttachAdditionalData(RcoBuffer* outDevice, bool bDir, const QString& str);
	void AttachAdditionalData(RcoBuffer* outDevice, bool bDir, const QByteArray& bytes);
	CmdHandlerResult OnFileGetting(RcoCommandHead* rcoCmdHead, RcoBuffer* outDevice);
	CmdHandlerResult OnDirectoryGetting(RcoCommandHead* rcoCmdHead, RcoBuffer* outDevice);

	qint64  totalSize;
	qint64  sizeFinished;
	QFile   file;
	QDir	dir;
	bool    bFileTransferring;
	bool    bDirTraversing;
	RDirCacheList   caches;
	RDirCacheList::Iterator current;
};


class PutCommandHandler
	: public IRCommandHandle
{
public:
	PutCommandHandler():m_create(false){}
	virtual CmdHandlerResult Do(RcoCommandHead* rcoCmdHead, const RcoBuffer* bytes, RcoIODevice* inDevice, RcoBuffer* outDevice);
private:
	CmdHandlerResult _createFileOrDir(RcoCommandHead* rcoCmdHead, const RcoBuffer* bytes);
	CmdHandlerResult _get_ProcessingConinue(RcoCommandHead* rcoCmdHead, const RcoBuffer* bytes);
	CmdHandlerResult _WriteFile(const RcoBuffer& bytes, const QString& fileName, QFile* file);
	void _errorClean();
	void _cleanDir();
private:
	QDir		m_dir;
	QDir		m_startDir;
	QFile		m_file;
	QString		m_fileName;
	QString		m_startFileName;
	bool		m_create;	
	RDirCacheList   caches;
	RDirCacheList::Iterator current;

};


//class SetBufCommandHandler
//	: public IRCommandHandle
//{
//public:
//	virtual CmdHandlerResult Do(const RcoCommandHead*, const QByteArray*);
//
//};
//
//class QProcessCommandHandler
//	: public IRCommandHandle
//{
//public:
//	virtual CmdHandlerResult Do(const RcoCommandHead*, const QByteArray*);
//
//};
//
//class KillCommandHandler
//	: public IRCommandHandle
//{
//public:
//	virtual CmdHandlerResult Do(const RcoCommandHead*, const QByteArray*);
//
//};
//
//class ShutdownCommandHandler
//	: public IRCommandHandle
//{
//public:
//	virtual CmdHandlerResult Do(const RcoCommandHead*, const QByteArray*);
//
//};

};

#endif // __RCO_CMD_HANDLER_H__